#set( $symbol_pound = '#' )
#set( $symbol_dollar = '$' )
#set( $symbol_escape = '\' )
package ${package}.common.enums;

import java.util.function.Function;
import ${package}.common.utils.DesensitizedUtil;

/**
 * 脱敏类型
 *
 * @author ruoyi
 */
public enum DesensitizedType
{
    /**
     * 姓名，第2位星号替换
     */
    USERNAME(s -> s.replaceAll("(${symbol_escape}${symbol_escape}S)${symbol_escape}${symbol_escape}S(${symbol_escape}${symbol_escape}S*)", "${symbol_dollar}1*${symbol_dollar}2")),

    /**
     * 密码，全部字符都用*代替
     */
    PASSWORD(DesensitizedUtil::password),

    /**
     * 身份证，中间10位星号替换
     */
    ID_CARD(s -> s.replaceAll("(${symbol_escape}${symbol_escape}d{4})${symbol_escape}${symbol_escape}d{10}(${symbol_escape}${symbol_escape}d{4})", "${symbol_dollar}1** **** ****${symbol_dollar}2")),

    /**
     * 手机号，中间4位星号替换
     */
    PHONE(s -> s.replaceAll("(${symbol_escape}${symbol_escape}d{3})${symbol_escape}${symbol_escape}d{4}(${symbol_escape}${symbol_escape}d{4})", "${symbol_dollar}1****${symbol_dollar}2")),

    /**
     * 电子邮箱，仅显示第一个字母和@后面的地址显示，其他星号替换
     */
    EMAIL(s -> s.replaceAll("(^.)[^@]*(@.*${symbol_dollar})", "${symbol_dollar}1****${symbol_dollar}2")),

    /**
     * 银行卡号，保留最后4位，其他星号替换
     */
    BANK_CARD(s -> s.replaceAll("${symbol_escape}${symbol_escape}d{15}(${symbol_escape}${symbol_escape}d{3})", "**** **** **** **** ${symbol_dollar}1")),

    /**
     * 车牌号码，包含普通车辆、新能源车辆
     */
    CAR_LICENSE(DesensitizedUtil::carLicense);

    private final Function<String, String> desensitizer;

    DesensitizedType(Function<String, String> desensitizer)
    {
        this.desensitizer = desensitizer;
    }

    public Function<String, String> desensitizer()
    {
        return desensitizer;
    }
}
